import { queryStockList, queryMarginTrading, queryInteractionList } from '@/services/tools';

export default {
  namespace: 'toolsModels',

  state: {
    stockList: {},
    marginTrading: {},
    questionList: {},
    replyList: {},
  },

  effects: {
    *queryStockList({ payload }, { call, put }) {
      // console.log("payload",payload)
      const response = yield call(queryStockList, payload);
      // console.log("response",response)
      yield put({
        type: 'setPayload',
        payload: {
          stockList: response.data,
        },
      });
    },
    *queryMarginTrading({ payload }, { call, put }) {
      const response = yield call(
        queryMarginTrading,
        payload.page_num,
        payload.page_size,
        payload.start_time,
        payload.end_time,
        payload.secu_code
      );
      console.log(response.data);
      yield put({
        type: 'setPayload',
        payload: {
          marginTrading: response.data,
        },
      });
    },
    *queryInteractionList({ payload }, { call, put }) {
      const response = yield call(
        queryInteractionList,
        payload.page_num,
        payload.page_size,
        payload.type
      );
      if (payload.type == 'question') {
        yield put({
          type: 'setPayload',
          payload: {
            questionList: response.data,
          },
        });
      } else {
        yield put({
          type: 'setPayload',
          payload: {
            replyList: response.data,
          },
        });
      }
    },
  },

  reducers: {
    setPayload(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};
